<?php
namespace Admin\Controller;

use Think\Controller;

class DataController extends Controller
{

    public function index()
    {

        $this->redirect('syndata/index');

    }

    public function receive()
    {

        $content = file_get_contents("php://input");

        if (!$content) {
            $unset = ['thinkphp_show_page_trace', 'pgv_pvi', 'PHPSESSID', 'pgv_si'];
            $content = $_REQUEST;

            $keys = array_keys($content);
            foreach ($keys as $key) {
                if (in_array((string)$key, $unset))
                    unset($content[$key]);
            }

        }

        if (!$content) {
            echo 'Miss.tang专属接口，目前没有接收到任何数据';
            exit;
        } else {
            if (is_array($content) && count($content) > 0) {
                $content = json_encode($content);
            }
        }


        $time = date("Y-m-d H:i:s");

        $ip = get_client_ip();

        if (!$ip) $ip = '0';
        $data = ['content' => $content, 'time' => $time, 'ip' => $ip, 'is_show' => 1];
        $id = M('syn')->add($data);
        if (!$id) {
            var_dump($data);
            $this->ajaxReturn('fail');
        }

        echo 'SUCCESS';

    }

    public function swoole()
    {

        if (IS_POST) {

            $post = I('post.');



            require getcwd().'/Swoole.php';


            $res = swoole($post);

            echo $res;

            exit;
        }

        echo 'empty';
    }

}